{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 跨进程通信"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 队列\n",
    "from multiprocessing import Queue\n",
    "\n",
    "q = Queue(3) \n",
    "\n",
    "# q.put(\"11\")\n",
    "# q.put(\"22\")\n",
    "# q.put(\"33\")\n",
    "# q.put(\"44\")\n",
    "# q.get(\"11\")\n",
    "# q.full()\n",
    "# q.empty()\n",
    "q.qsize()  # NotImplementedError"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 'hello', None]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 管道\n",
    "from multiprocessing import Pipe\n",
    "\n",
    "a, b = Pipe()\n",
    "\n",
    "a.send([1, 'hello', None])\n",
    "\n",
    "b.recv()\n",
    "# [1, 'hello', None]\n",
    "\n",
    "# b.send_bytes(b'thank you')\n",
    "\n",
    "# a.recv_bytes()\n",
    "# b'thank you'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.7 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "7e1998ff7f8aa20ada591c520b972326324e5ea05489af9e422744c7c09f6dad"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
